package com.itheima.web.controller;

import com.itheima.domain.mongo.Questionnaire;
import com.itheima.pojo.Answer;
import com.itheima.web.manager.SoulManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
public class SoulController {
    @Autowired
    private SoulManager soulManager;
    @PostMapping("/questionnaires/page")
    //展示全部问卷的接口
    public ResponseEntity findPage(@RequestParam(value = "page",defaultValue = "1")Integer pageNum,@RequestParam(value = "pagesize",defaultValue = "10")Integer pageSize)

    {
       return soulManager.findPage(pageNum,pageSize);
    }
    @PostMapping("/questionnaires/findById")
    public ResponseEntity findById(@RequestParam("id") String id)
    {
        return soulManager.findById(id);
    }
    @PostMapping("/questionnaires/save")
    public ResponseEntity save(@RequestBody Questionnaire questionnaire)
    {
        return soulManager.save(questionnaire);
    }
    @PostMapping("/questionnaire/upload")
    public ResponseEntity uploadFile( @RequestPart(value="uploadFile")MultipartFile files) throws IOException {
        return soulManager.uploadFile(files);
    }
    @PostMapping("/questionnaires/delete")
    public ResponseEntity deleteByIds(@RequestBody String params)
    {
        String[] ids = params.split(",");
        return soulManager.deleteByIds(ids);
    }
}
